<?php
/**
 * Nuclide Loader
 * 
 * @package Nuclide
 * @author	Mats Lundberg 
 * @version $Id$
 */

// Include the Abstract class
include_once( dirname(__FILE__) . '/nuc_loader_abstract.class.php' );

/**
 * Load classes from files according to certain rules. Useful for lazy inclusion of php files.
 * 
 * @package Nuclide
 * @author	Mats Lundberg 
 * @todo	Advanced ruleset. Make it like the Zend_View includer.
 */
class nuc_Loader extends nuc_Loader_Abstract
{
	/**
	 * Convert an identification name and type to a filename
	 *
	 * @param	string	Name
	 * @param	string 	File type (class|func)
	 * @return	Path
	 */
	private function identToFilename( $name, $type ) {
		$name = strtolower( $name );
		if( strstr( $name, '.' ) ) {
			$name = explode( '.', $name );
			$path = implode( '/', array_slice( $name, 0, count( $name ) - 1 ) ) . '/' . end( $name ) . '.' . $type . '.php';
		} else {
			$path = $name . '.' . $type . '.php';
		}

		return $path; 
	}
	
	/**
	 * Convert class name to filename
	 *
	 * @param	string	Class name
	 * @return	Path
	 */
	public function classToFilename( $className ) {
		return $this->identToFilename( $className, 'class' );
	}
	
	/**
	 * Convert functions category to filename. Useful in situations when you want to have a file 
	 * with a bunch of function to include.
	 *
	 * @param 	string	Functions file name 
	 * @return	Path
	 */
	protected function functionsToFilename( $functionsName ) {
		return $this->identToFilename( $functionsName, 'func' );
	}
}
?>